import java.time.LocalTime;

public class Thermostat {
    private static final int MIN_TEMPERATURE = 20;
    private static final int MAX_TEMPERATURE = 100;
    private static final LocalTime SLEEP_TIME = LocalTime.of(23, 0);
    private static final LocalTime WAKE_UP_TIME = LocalTime.of(7, 0);

    private boolean isTankBroken;
    private boolean isSleeping;
    private int temperature;
    private int waterLevel;

    public Thermostat() {
        this.isTankBroken = false;
        this.isSleeping = false;
        this.temperature = MIN_TEMPERATURE;
        this.waterLevel = 0;
    }

    public void updateTemperature(int temperature) {
        this.temperature = temperature;
        checkTemperature();
    }

    public void updateWaterLevel(int waterLevel) {
        this.waterLevel = waterLevel;
        checkTemperature();
    }

    public void checkTemperature() {
        if (isSleeping) {
            return;
        }

        if (isTankBroken) {
            System.out.println("Tank is broken. Please repair.");
            return;
        }

        if (temperature < MIN_TEMPERATURE && waterLevel > 0) {
            startHeating();
        } else if (temperature >= MAX_TEMPERATURE) {
            stopHeating();
        }
    }

    public void startHeating() {
        System.out.println("Heating started.");
    }

    public void stopHeating() {
        System.out.println("Heating stopped.");
    }

    public void repairTank() {
        isTankBroken = false;
        System.out.println("Tank repaired.");
    }

    public void setSleeping(boolean isSleeping) {
        this.isSleeping = isSleeping;
        if (isSleeping) {
            stopHeating();
            System.out.println("Entering sleep mode.");
        } else {
            System.out.println("Waking up from sleep mode.");
        }
    }

    public static void main(String[] args) {
        Thermostat thermostat = new Thermostat();

        // 模拟温度和水位变化
        thermostat.updateTemperature(15);
        thermostat.updateWaterLevel(50);
        thermostat.updateTemperature(25);
        thermostat.updateWaterLevel(0);
        thermostat.updateTemperature(100);
        thermostat.updateWaterLevel(50);

        // 模拟晚上11点进入睡眠模式
        LocalTime currentTime = LocalTime.of(23, 0);
        thermostat.setSleeping(currentTime.isAfter(SLEEP_TIME) && currentTime.isBefore(WAKE_UP_TIME));

        // 模拟早上7点醒来
        currentTime = LocalTime.of(7, 0);
        thermostat.setSleeping(currentTime.isAfter(SLEEP_TIME) && currentTime.isBefore(WAKE_UP_TIME));
    }
}
